#### Table 4: Group Threat on Gender Norms (Study 2) ####
## Author: Jeong Hyun Kim
## Last updated: 12/28/2021

#### Study 2: Loading Data and Coding Variables ####
df <- read.spss("survey2021.sav", to.data.frame = TRUE, use.value.labels = FALSE)

# Create a variable that denotes respondents who passed manipulation check:
df <- df %>% mutate(T1_pass = case_when(K0 == 1 & K1==1  ~ 1,
                                        K0 == 1 & K1==2 ~ 0),
                    T2_pass = case_when(K0 == 2 & K2 ==1 ~ 1,
                                        K0 == 2 & K2 == 2 ~ 0))
table(df[which(df$K0==1), "T1_pass"])
table(df[which(df$K0==2), "T2_pass"])

# Reduce the sample to those who passed the manipulation check:
df <- df[which(df$T1_pass==1 | df$T2_pass==1), ]

# code the respondents who received "T1" as treated:
df <- df %>% mutate(treated = case_when(K0 == 1 ~ 1,
                                        K0 == 2 ~ 0))

df$young1 <- ifelse(df$BQ3 < 40, 1, 0)
# Alternative operationalization of young variable
df$young2 <- ifelse(df$BQ3 < 40 & df$BQ3 > 25, 1, 0)
# Alternative operationalization of young variable
df$young3 <- ifelse(df$BQ3 < 41 & df$BQ3 > 24, 1, 0)  
df$young4 <- ifelse(df$BQ3 < 35 & df$BQ3 > 19, 1, 0)  # 20-34

df<-  df %>% rename(age = BQ3,
                    education = BQ4,
                    occupation = BQ5,
                    job_status = BQ5_3,
                    region = BQ1,
                    income = BQ12_1,
                    ideology = BQ13,
                    religion = BQ8,
                    marital_status = BQ6,
                    gender_quota_att = K3_1,
                    equal_pay = K3_2,
                    corporate_quota = K3_3
)
df <- df %>% rename(male_status = K6,
                    female_status = K7)

df <- df %>% mutate(children = case_when(ABQ7 == 1 ~ 1,
                                         ABQ7 == 2 ~ 0),
                    econ_bad = ifelse(K9==1| K9==2, 1, 0))
## gender norms
# K5_1: 가사노동 (lower value indicates more related to men)
# K5_2: 사업 (lower value indicates more related to men)
# K5_3: 육아 (lower value indicates more related to men)
# K5_4: 정치 
df <- df %>% mutate(gender_norm_1 = ifelse(K5_1==5| K5_1==6| K5_1==7, 1, 0),
                    gender_norm_2 = ifelse(K5_2==1| K5_2==2 | K5_2 ==3, 1, 0),
                    gender_norm_3 = ifelse(K5_3==5| K5_3==6| K5_3==7, 1, 0),
                    gender_norm_4 = ifelse(K5_4==1| K5_4==2| K5_4==3, 1, 0))

df$age.group <- NA
df[which(df$age < 30), "age.group"] <- " under 30"
df[which(df$age > 29 & df$age < 40), "age.group"] <- "30s"
df[which(df$age > 39 & df$age < 50), "age.group"] <- "40s"
df[which(df$age > 49 & df$age < 60), "age.group"] <- "50s"
df[which(df$age > 59 ), "age.group"] <- "60 and older"


df.men <- df %>% filter(BQ2=="1")
df.women <- df %>% filter(BQ2=="2")

#### Table 4 ####
model1 <- glm(gender_norm_1 ~ treated*young1, family="binomial", df.men)
model2 <- glm(gender_norm_2 ~ treated*young1, family="binomial", df.men)
model3 <- glm(gender_norm_3 ~ treated*young1, family="binomial", df.men)
model4 <- glm(gender_norm_4 ~ treated*young1, family="binomial", df.men)
model5 <- glm(gender_norm_1 ~ treated*young1,family="binomial", df.women)
model6 <- glm(gender_norm_2 ~ treated*young1,family="binomial", df.women)
model7 <- glm(gender_norm_3 ~ treated*young1,family="binomial", df.women)
model8 <- glm(gender_norm_4 ~ treated*young1,family="binomial", df.women)

stargazer(model1, model5, model2, model6, model3, model7, model4, model8,
          type = "latex", header=FALSE, title = "The Effect of Status Threat on Gender Norm",
          dep.var.labels = c("Housework-Women", "Business-Men", "Childcare-Women", "Politics-Men"),
          cov.var.labels = c("Treated", "Young", "Treated:Young", "Constant"))

